package com.four.peoplemanage.exit.service;

import com.four.peoplemanage.common.bean.Page;
import com.four.peoplemanage.exit.dao.ExitDao;
import com.four.peoplemanage.exit.entity.Exit;
import com.four.peoplemanage.overtime.entity.Overtime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ExitService {
    @Autowired
    ExitDao exitDao;
    //申请加班
    public boolean insert(Exit exit){
        if (exit == null){
            return false;
        }
        exit.setLook_status("是");
        exit.setStatus("待审核");
        return exitDao.addExit(exit)>0;
    }

    //分页
    public Page<Exit> getPageExit (int pageNum, int pageSize, String name, String persionstatus, String office,String status){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Exit> list=exitDao.getExit(start,pageSize,name,persionstatus,office,status);
        //获取总条目数
        int total=exitDao.countExit(name,persionstatus,office,status);
        //计算总页数
        int pages =(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Exit> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    //分页
    public Page<Exit> getOneExit (int pageNum, int pageSize, String name, String persionstatus, String office,int information_id,String status){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Exit> list=exitDao.getOneExit(start,pageSize,name,persionstatus,office,information_id,status);
        //获取总条目数
        int total=exitDao.countExit(name,persionstatus,office,status);
        //计算总页数
        int pages =(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Exit> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    //撤销
    public  boolean updateStatus(Exit exit){
        if (exit==null){
            return false;
        }
        exit.setStatus("已撤销");
        return exitDao.updateExit(exit)>0;
    }

    //审核通过
    public  boolean updateSuccess(Exit exit){
        if (exit==null){
            return false;
        }
        exit.setStatus("已通过");
        return exitDao.updateExit(exit)>0;
    }

    //审核驳回
    public  boolean updateFail(Exit exit){
        if (exit==null){
            return false;
        }
        exit.setStatus("已驳回");
        return exitDao.updateExit(exit)>0;
    }

    //编辑
    public boolean updateOvertime(Exit exit){
        if (exit == null){
            return false;
        }
        exit.setStatus("待审核");
        return exitDao.updateExitById(exit)>0;
    }
}
